<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>添加/修改管理员</title>
<link href="__PUBLIC__/admin/css/xc.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/xc.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.js"></script> 
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.admin.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/common-1.0.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
</head>
<body>
<div class="pd-20">
  <form action="" method="post" class="form form-horizontal" id="myform">
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>用户名：</label>
      <div class="formControls col-9">
        <input type="text" id="uname" name="uname" value="{$ure.ad_name}" class="input-text" placeholder="请输入管理员姓名">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>密　码：</label>
      <div class="formControls col-9">
        <input type="text" id="pwds" name="pwds" class="input-text" placeholder="请输入6~18位密码组合">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>手机号：</label>
      <div class="formControls col-9">
        <input type="text" id="phone" name="phone" value="{$ure.ad_phone}" class="input-text" placeholder="请输入您常用的手机号">
      </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>邮　箱：</label>
      <div class="formControls col-9">
        <input type="text" id="email" name="email" value="{$ure.ad_email}" class="input-text" placeholder="请输入您常用的邮箱">
      </div>
    </div>
    <div class="row cl">
	  <label class="form-label col-2"><span class="c-red">*</span>权限分配：</label>
	  <div class="formControls col-9">
        <foreach name="modules" item="menu" key="kk">	
        <dl class="permission-list">
          <dt><label><input type="checkbox" value="1" cka="mod-{$kk}"> {$rtype[$kk]}</label></dt>
          <dd>
            <dl class="cl permission-list2">
              <dd>
                <foreach name="menu" item="vv">
                <label><input type="checkbox" name="right[]" value="{$vv.me_id}" ck="mod-{$kk}" <if condition="($vv[enable] eq 1)">checked</if> > {$vv.me_name}</label>
                </foreach>
              </dd>
            </dl>
          </dd>
        </dl>
        </foreach>
      </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <input type="hidden" name="uid" value="{$ure.ad_id}">
        <input type="hidden" name="act" value="{$act}">
        <button type="button" id="sub" name="sub" class="btn btn-primary radius" onClick="checkSubmit()"><i class='Hui-iconfont'>&#xe632;</i> 保存</button>
        <button class="btn btn-default radius" type="button" onClick="layer_close();"><i class='Hui-iconfont'>&#xe66b;</i> 取消</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$(":checkbox[cka]").click(function(){
		var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
		if($(this).is(':checked')){
			$cks.each(function(){$(this).prop("checked",true);});
		}else{
			$cks.each(function(){$(this).removeAttr('checked');});
		}
	});
});
//按回车件触发提交
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){ // enter 键
		checkSubmit();
	}
}; 
//提交数据
function checkSubmit()
{
	var uname = $.trim($('#uname').val());
	var phone = $.trim($('#phone').val());
	var email = $.trim($('#email').val());
	if(uname == ''){
		layer.msg('用户名不能为空', {icon: 2});
		return false;
	}if(phone == ''){
		layer.msg('用户手机不能为空!', {icon: 2});
		return false;
	}if(!checkMobile(phone)){
		layer.msg('手机号码格式不正确!', {icon: 2});
		return false;
	}if(email == ''){
		layer.msg('用户邮箱不能为空!', {icon: 2});
		return false;
	}if(!checkEmail(email)){
		layer.msg('邮箱格式不正确!', {icon: 2});
		return false;
	}
	$.ajax({
		type : 'post',
		url : '__MODULE__/Role/adminAddEdit',
		data : $("#myform").serialize(),
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				layer.msg(res.msg,{icon:1,time:2000},function(){
					// 先获取窗口索引，才能关闭窗口  
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
				parent.call_back_fun('success');
			}else{
				layer.msg(res.msg, {icon: 2});
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.alert('网络失败，请刷新页面后重试',{icon:2});
		}
	})
}
</script>
</body>
</html>